package com.example.auth.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;

/**
 * @ClassName AuthServerConfig
 * @Description TODO
 * @Author leejiliang
 * @DateTime 2020/4/26 11:16 AM
 * @Version 1.0
 */
@EnableAuthorizationServer
@Configuration
public class AuthServerConfig extends AuthorizationServerConfigurerAdapter {
	@Autowired
	private PasswordEncoder passwordEncoder;

	@Override
	public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
		clients.inMemory()
				.withClient("lee")
				.secret(passwordEncoder.encode("lee"))
				.autoApprove(true)
				.redirectUris("http://localhost:1112/login", "http://localhost:1113/login")
				.scopes("user")
				.accessTokenValiditySeconds(7200)
				.authorizedGrantTypes("authorization_code");

	}
}
